class weixinManager {
	private selfUserInfo: any;
	private code: any;
	private constructor() {

	}
	private static instance: weixinManager;
	public static getInstance(): weixinManager {
		if (this.instance == null) {
			this.instance = new weixinManager();
		}
		return this.instance;
	}
	/**获取微信授权拒绝后再允许调用 */
	public tiao() {
		SceneManager.instance.SitchScene(SceneName.登录场景);
	}
	public async askAccredit(ongetOpenid: Function, onGetComplete: Function) {
		//await platform.showShareMenu();
		const res = await platform.login();
		//	console.log("获取到的微信code：" + res.code);
		const userInfo = await platform.getUserInfo(this.tiao)
		if (userInfo == null) {
			DataProl.huoqu = false;
		} else {
			gameGlobal.global.playerName = userInfo.nickName;
			DataProl.huoqu = true;
		}
		if (GlobalData.isweixin) {
			this.setUserInfo(userInfo);
			if (res != null)
				this.setCode(res.code);
			ongetOpenid(onGetComplete);
		}
	}
	public getUserInfo(): any {
		if (this.selfUserInfo == null) {
			console.log("未接受到微信信息");
		}
		return this.selfUserInfo;
	}
	private setUserInfo(data: any): void {
		this.selfUserInfo = data;
	}
	private setCode(data: any) {
		this.code = data;
	}

	public getCode() {
		if (this.code != null) {
			return this.code;
		}
	}
	//主动调起转发
	private async zhuDongShare(fn) {
		var res = await platform.activeShare(0);
		//res = JSON.stringify(res);
		console.log("转发之后结果：" + res.errMsg);
		if (res.errMsg == "shareAppMessage:ok") {
			console.log("转发成功");
			//调用转发成功后的操作
			fn();
		}
	}
	/**分享 */
	public clikShare() {
		this.zhuDongShare(e => {
			console.log("执行转发成功之后的操作");
		}).catch(e => {
			console.log("按钮绑定点击事件");
		});
	}
}